package com.scf.loanmanage.service.ServiceImp;

import com.scf.loanmanage.dao.LoanLevelFiveMapper;
import com.scf.loanmanage.entity.LoanLevelFive;
import com.scf.loanmanage.service.LoanLevelFiveService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class LoanLevelFiveImpl implements LoanLevelFiveService {
    @Resource
    LoanLevelFiveMapper loanLevelFiveMapper;

    @Override
    public List<LoanLevelFive> selectAll(Integer pageIndex, Integer pageSize) {
        return loanLevelFiveMapper.selectAll(pageIndex, pageSize);
    }

    @Override
    public Integer selectcount() {
        return loanLevelFiveMapper.selectcount();
    }

    @Override
    public List<LoanLevelFive> selectByname(String enterprisename, String code) {
        return loanLevelFiveMapper.selectByname(enterprisename, code);
    }

    @Override
    public void insertFive(LoanLevelFive loanLevelFive) {

        //判断表中是否有
        List<LoanLevelFive> loanLevelFives = loanLevelFiveMapper.selectAlls();
        for(LoanLevelFive loanLevelFive1 :loanLevelFives){
            if(loanLevelFive1.getEnterprisename().equals(loanLevelFive.getEnterprisename())){
                System.out.println("-----");
                return;
            }
        }
        System.out.println("++++++++");
        if(loanLevelFive.getBorrowedterm()<=10000.00 && loanLevelFive.getBorrowedterm()<=1){
            loanLevelFive.setLevel("正常");
            loanLevelFive.setBorrowingvarieties("应收账款保理");
            loanLevelFive.setRepaymentstatus("未逾期");
            System.out.println("++1");
        }else if(loanLevelFive.getBorrowedterm()>=10000.00 && loanLevelFive.getBorrowedterm()<=2){
            loanLevelFive.setLevel("关注");
            loanLevelFive.setBorrowingvarieties("短期贷");
            loanLevelFive.setRepaymentstatus("逾期");
            System.out.println("++2");
        }else if(loanLevelFive.getBorrowedterm()>=100000.00 && loanLevelFive.getBorrowedterm()<=3){
            loanLevelFive.setLevel("次级");
            loanLevelFive.setBorrowingvarieties("中期贷");
            loanLevelFive.setRepaymentstatus("逾期");
            System.out.println("++3");
        }else if(loanLevelFive.getBorrowedterm()>=100000 && loanLevelFive.getBorrowedterm()>=5){
            loanLevelFive.setLevel("损失");
            loanLevelFive.setBorrowingvarieties("长期贷");
            loanLevelFive.setRepaymentstatus("逾期");
            System.out.println("++4");
        }else {
            System.out.println("都不满足");
            loanLevelFive.setLevel("损失");
            loanLevelFive.setBorrowingvarieties("长期贷");
            loanLevelFive.setRepaymentstatus("逾期");
            System.out.println("++4");
        }


        loanLevelFiveMapper.insertFive(loanLevelFive);
    }

    @Override
    public List<LoanLevelFive> selectAlls() {
        return loanLevelFiveMapper.selectAlls();
    }
}
